<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title th:replace="common/base::pagetitle"></title>
    <link th:replace="common/base::static"/>
    <link rel="stylesheet" th:href="@{/static/plugins/easyui/themes/material/easyui.css}">
    <link rel="stylesheet" th:href="@{/static/plugins/easyui/themes/icon.css}">
    <link rel="stylesheet" th:href="@{/static/css/wlb-treegrid.css}">
</head>
<body style="background-color: #f2f2f2;">

<div id="kPage" class="layui-fluid" style="padding: 0">
    <div class="layui-row">
        <!-- 主要内容块 -->
        <div class="layui-col-md12" id="kMainContentCol">
            <div class="layui-fluid wlb-fluid-padding15">
                <div class="layui-card">
                    <form>
                        <div class="layui-form layui-card-header wlb-card-header-auto">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">名称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <button class="layui-btn " lay-submit="" lay-filter="kTableSearchFilter">
                                        <i class="layui-icon layui-icon-search"></i>
                                    </button>
                                    <button class="layui-btn " type="reset">
                                        <i class="layui-icon layui-icon-refresh-1"></i>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </form>

                    <div class="layui-card-body">
                        <table id="kContentTable" lay-filter="kContentTable"></table>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>

<script th:replace="common/base::context"></script>
<script th:replace="common/base::mainjs"></script>
<script th:src="@{/static/plugins/easyui/easyloader.js}"></script>

<script type="text/html" id="statusTpl">
    {{# if(d.status === 0) { }}
    <span class="layui-badge layui-bg-green">正常</span>
    {{# } else { }}
    <span class="layui-badge layui-bg-gray">禁用</span>
    {{# } }}
</script>

<script type="text/html" id="typeTpl">
    {{#  if(d.type === 0){ }}
    <span class="layui-badge layui-bg-blue">供应商</span>
    {{#  } else if(d.type === 1) { }}
    <span class="layui-badge layui-bg-orange">核心企业</span>
    {{#  } else if(d.type === 2) { }}
    <span class="layui-badge layui-bg-green">银行</span>
    {{#  } else { }}
    <span class="layui-badge layui-bg-cyan">其他</span>
    {{# } }}
</script>

<script type="text/html" id="sourceTpl">
    {{#  if(d.source == 0){ }}
    <span class="layui-badge layui-bg-blue">集采推送</span>
    {{#  } else if(d.source == 1) { }}
    <span class="layui-badge layui-bg-orange">其他</span>
    {{# } }}
</script>





<!--表格行工具栏模板-->
<script type="text/html" id="rowToolbarTpl">
    <a class="layui-btn layui-bg-orange layui-btn-xs" onclick="active.add(this)" data-id="{{d.id}}" data-compId="{{d.comId}}"><i class="layui-icon layui-icon-add-1"></i>添加账号</a>
    <a class="layui-btn layui-btn-normal layui-btn-xs" onclick="active.account_list(this)"  data-id="{{d.id}}"  lay-event="info"><i class="layui-icon layui-icon-search"></i>账号列表</a>
</script>

<script type="text/javascript" th:inline="none">
    var active;
    layui.use(['element', 'form', 'layer', 'table', 'laytpl'], function () {
        var elemet = layui.element, form = layui.form, layer = layui.layer, table = layui.table;
        var tableId = 'kContentTable';

        // 实例化table
        var tableIns = table.render($.extend(config.layui.table, {
            elem: '#' + tableId
            , url: api.sys.deptListData + "?type="+ 0//数据接口
            , toolbar: '#headToolbarTpl'
            , cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                , {field: 'name', title: '机构名称', width: 120, fixed: false}
                // , {field: 'accountId', title: '签名账号',  width: 180}
                , {field: 'type', title: '类型', width: 100, align: 'center', templet: '#typeTpl', fixed: false}
                , {field: 'comAddress', title: '公司地址',  width: 220, fixed: false}
                , {field: 'admMobPhone', title: '联系电话',  width: 220, fixed: false}
                , {field: 'comCerNo', title: '工商注册号',  width: 220, fixed: false}
                , {field: 'source', title: '机构来源',  width: 100, templet: '#sourceTpl', fixed: false}
                , {field: '', title: '操作', width: 370, fixed: 'right', templet: '#rowToolbarTpl'}
            ]]
        }));
        var area = ['450px', '530px'];

        // 监听事件
        active = {

            add:function (that) {
                var id = $(that).data('id');
                var area2 = ['80%', '80%'];
                var index = layer.open({
                    type: 2
                    , title: '授信通过列表'
                    , content: api.orgAccount.orgAdoptBankView + "?compId="+id
                    , maxmin: true
                    , area: area2   // 宽高
                    // , btn: ['确定', '取消']
                    // , yes: function (index, layero) {
                    // 	//点击确认触发 iframe 内容中的按钮提交
                    // 	debugger
                    // 	var submit = layero.find('iframe').contents().find("#kTableSubmit");
                    // 	submit.click();
                    // }
                });
                // layer.full(index);
            },

            account_list:function (that) {
                var id = $(that).data('id');
                var area2 = ['80%', '80%'];
                var index = layer.open({
                    type: 2
                    , title: '账号列表'
                    , content: api.orgAccount.orgAdoptAccountView + "?compId="+id
                    , maxmin: true
                    , area: area2   // 宽高
                    // , btn: ['确定', '取消']
                    // , yes: function (index, layero) {
                    // 	//点击确认触发 iframe 内容中的按钮提交
                    // 	debugger
                    // 	var submit = layero.find('iframe').contents().find("#kTableSubmit");
                    // 	submit.click();
                    // }
                });
                // layer.full(index);
            },



        };

        wlbKit.activeInit(active);

        $(window).resize(function () {
            treeGridKit.fitRightFrozenCol(tableId);
        });

        // 列格式化函数
        var formatter = {
            rowToolbar: function (value, row, index) {
                return wlbKit.renderTpl('rowToolbarTpl', row);
            },
            status: function (value, row, index) {
                return wlbKit.renderTpl('statusTpl', row);
            },
            type: function (value, row, index) {
                return wlbKit.renderTpl('typeTpl', row);
            },
            source: function (value, row, index) {
                return wlbKit.renderTpl('sourceTpl', row);
            }
        };

        // 监听查询
        form.on('submit(kTableSearchFilter)', function (obj) {
            var params = obj.field;
            log('seach=', params); //

            tableIns.reload({
                where: params,
                page: {curr: 1}
            });
            return false;

        });

        // 绑定监听回车事件
        wlbKit.bindEnterEventForLayuiForm();

    });
</script>

</body>
</html>
